import request from "@/utils/request";
const defaultApi = (apiName) => {
    return {
        list: (params) => request.get(`/${apiName}/list`, { params }),
        page: (params) => request.get(`/${apiName}`, { params }),
        read: (id) => request.get(`/${apiName}/` + id),
        create: (id, data) => request.post(`/${apiName}`, data),
        update: (id, data) => request.put(`/${apiName}/` + id, { ...data, create_time: undefined, id: undefined }),
        delete: (id) => request.delete(`/${apiName}/` + id)
    }
}
export const http = {
    user: {
        ...defaultApi('user'),
        login: (data) => request.post('/user/login', data),
        // 注册
        register: (data) => request.post('/user/register', data),
        getUserInfo: (userId) => request.get(`/user/getUserInfo`, { params: { userId }}),
        update: (id, data) => request.put(`/user/${id}`, data),
        updatePassword: (data) => request.put(`/user/updatePassword`, data),
    },
    conversation: {
        ...defaultApi('conversation')
    },
    message: {
        ...defaultApi('message')
    },
    mj: {
        create: (params) => request.post('/mj/create', params),
        fetch: (params) => request.get('/mj/fetch', { params }),
        action: (params) => request.post('/mj/action', params),
        model: (params) => request.post('/mj/model', params),
    },
    model: {
        ...defaultApi('model'),
        userList: (data) => request.get('/model/userList', { params: data })
    }
}
// uploadFile
export const uploadFile = (file) => {
    const formData = new FormData()
    formData.append('file', file)
    return request({
        url: '/upload/file',
        method: 'post',
        data: formData
    })
}
